<?php
include_once 'koneksi.php';
class Member
{
	public function __construct (){
		$this-> koneksi = new Koneksi();
	} //<!--end of __construct-->
	
	public function addnewmember($id_user,$id_userkat,$password,$namadepan,$namabelakang,$alamatuser,$notelpuser,$kotauser,$emailuser,$kodeposuser,$fotouser){
		if(($id_user=="") or 
		($password=="") or 
		($namadepan=="") or 
		($namabelakang=="") or 
		($alamatuser=="") or 
		($notelpuser=="") or 
		($kotauser=="") or 
		($emailuser=="") or 
		($kodeposuser=="")){
			return false;
		}
		$this->koneksi->_connect();
		$pass2=md5($password);
		$query = "INSERT INTO `pronsweb`.`user` (
			`ID_USER` ,
			`ID_USERKAT` ,
			`PASSWORD` ,
			`NAMADEPAN` ,
			`NAMABELAKANG` ,
			`ALAMATUSER` ,
			`NOTELPUSER` ,
			`KOTAUSER` ,
			`EMAILUSER` ,
			`KODEPOSUSER` ,
			`FOTOUSER`
			)
			VALUES (
			'$id_user','$id_userkat','$pass2','$namadepan','$namabelakang','$alamatuser','$notelpuser','$kotauser','$emailuser','$kodeposuser','$fotouser'
			);";
		$result = mysql_query($query, $this-> koneksi -> db);
		$this->koneksi->_close();
		if ($result) {
			echo "sucsess";
			return true;
		} else {
			echo "gagal";
			return false;
		}
	}//<!--end of adnewmember-->
	
	public function getMember(){
		$this->koneksi->_connect();
		$query = "select * from user where id_userkat = 2";
		$result = mysql_query($query);
		while ($data = mysql_fetch_array($result)) {
			$array[$data['ID_USER']]=new Member2($data['ID_USER'], $data['NAMADEPAN'], $data['NAMABELAKANG'], $data['ALAMATUSER'], $data['NOTELPUSER'], $data['KOTAUSER'], $data['EMAILUSER'], $data['KODEPOSUSER']);
		}
		$this->koneksi->_close();
		if (!empty($array))
		{
			return $array;
		}
	}//<!--end of getMember-->
	
		public function getMemberDetail($id_user){
		$this->koneksi->_connect();
		$query = "select * from user where id_user='$id_user'";
		$result = mysql_query($query);
		while ($data = mysql_fetch_array($result)) {
			$array[$data['ID_USER']]=new Member2($data['ID_USER'], $data['NAMADEPAN'], $data['NAMABELAKANG'], $data['ALAMATUSER'], $data['NOTELPUSER'], $data['KOTAUSER'], $data['EMAILUSER'], $data['KODEPOSUSER']);
		}
		$this->koneksi->_close();
		if (!empty($array))
		{
			return $array;
		}
	}//<!--end of getMemberDetail-->
	
	public function getAdmin(){
		$this->koneksi->_connect();
		$query = "select * from user where id_userkat = 1";
		
		$result = mysql_query($query);
		while ($data = mysql_fetch_array($result)) {
			$array[$data['ID_USER']]=new Member2($data['ID_USER'], $data['NAMADEPAN'], $data['NAMABELAKANG'], $data['ALAMATUSER'], $data['NOTELPUSER'], $data['KOTAUSER'], $data['EMAILUSER'], $data['KODEPOSUSER']);
		}
		$this->koneksi->_close();
		if (!empty($array))
		{
			return $array;
		}
	}//<!--end of getAdmin-->
	
	public function  updateMember($id_user,$id_userkat,$password,$namadepan,$namabelakang,$alamatuser,$notelpuser,$kotauser,$emailuser,$kodeposuser,$fotouser){
		$this->koneksi->_connect();
		$query = mysql_query("UPDATE user SET password ='$password', namadepan='$namadepan', namabelakang='$namabelakang', alamatuser = '$alamatuser', notelpuser = '$notelpuser', kotauser = '$kotauser', emailuser = '$emailuser', kodeposuser = '$kodeposuser', fotouser = '$fotouser' WHERE id_user = '$id_user' and id_userkat = '$id_userkat';");
		$this->koneksi->_close();
		return true;
	}//<!--end of updateMember-->	

	public function  deleteMember($id_user){
		$this->koneksi->_connect();
		$query = mysql_query("DELETE FROM `user` WHERE id_user = '$id_user';");	
		$this->koneksi->_close();
		return true;
	}//<!--end of deleteMember-->
}


class Member2 {
	public $id_user;
	public $id_userkat;
	public $password;
	public $namadepan;
	public $namabelakang;
	public $alamatuser;
	public $notelpuser;
	public $kotauser;
	public $emailuser;
	public $kodeposuser;
	public $fotouser;
	
	public function __construct($id_user, $namadepan, $namabelakang, $alamatuser, $notelpuser, $kotauser, $emailuser, $kodeposuser)  
    {  
        $this->id_user = $id_user;
	    $this->namadepan= $namadepan;
		$this->namabelakang = $namabelakang;
		$this->alamatuser = $alamatuser;
		$this->notelpuser = $notelpuser;
		$this->kotauser = $kotauser;
		$this->emailuser = $emailuser;
		$this->kodeposuser = $kodeposuser;
    } 
}
?>